package whf.framework.security.entity;

import whf.framework.entity.AbstractEntity;
import whf.framework.entity.Permissionable;

/**
 * 对什么有怎样的权限
 * 描述为，对哪些资源拥有哪些权限
 * @author wanghaifeng
 * 
 * <OL>
 * <li>袮补Acegi的缺陷，使得资源可以动态分配，即可以通过配置实现Spring服务方法的权限控制，也可以通过自己实现拦截器控制</li>
 * <li>通过控制Struts的方法权限实现界面等的权限后台的权限大统一；</li>
 * <li>可以实现记录级别的权限</li>
 * <li></li>
 * </OL>
 */
public class Permission extends AbstractEntity implements Permissionable {
	public final static String PERMISSION_TYPE_MENU = "MENU";
	
	/**
	 * 对象目标，通常指对象
	 * 对象类型，通常来自于元数据
	 * 对于菜单有两种情况：1、一种业务对象，与其它对象一样管理，2、是否可以在菜单中显示，其实与其它属性无关
	 */
	private String target;
	
	/**
	 * 操作类型，struts方法名称，可以判定一个用户是否可以执行一个struts方法，往往方法是成对出现的
	 * 如：create和prepareCreate;
	 * 本系统中主要使用struts方法判断
	 */
	private String operation;
	
	/**
	 * 操作准备，往往是与Operation对应的
	 * 根据命名规则，这两个对象方法拥有相同的权限
	 * @property String:preOperation
	 */
	private String prepareOperation;
	
	/**
	 * 对应的service中的操作方法名称，不是不许的；
	 */
	private String serviceOperation;
	
	/**
	 * 权限类型,如菜单权限,主要用来过滤作用
	 */
	private String type;

	/* (non-Javadoc)
	 * @see whf.framework.auth.entity.IPermission#getPrepareOperation()
	 */
	public String getPrepareOperation() {
		return prepareOperation;
	}

	/* (non-Javadoc)
	 * @see whf.framework.auth.entity.IPermission#setPrepareOperation(java.lang.String)
	 */
	public void setPrepareOperation(String prepareOperation) {
		this.prepareOperation = prepareOperation;
	}

	/* (non-Javadoc)
	 * @see whf.framework.auth.entity.IPermission#getTarget()
	 */
	public String getTarget(){
		return this.target;
	}

	/* (non-Javadoc)
	 * @see whf.framework.auth.entity.IPermission#setTarget(java.lang.String)
	 */
	public void setTarget(String obj){
		this.target = obj;
	}

	/* (non-Javadoc)
	 * @see whf.framework.auth.entity.IPermission#getOperation()
	 */
	public String getOperation(){
		return this.operation;
	}

	/* (non-Javadoc)
	 * @see whf.framework.auth.entity.IPermission#setOperation(java.lang.String)
	 */
	public void setOperation(String opt){
		this.operation = opt;
	}
	
	/* (non-Javadoc)
	 * @see whf.framework.auth.entity.IPermission#getServiceOperation()
	 */
	public String getServiceOperation() {
		return serviceOperation;
	}

	/* (non-Javadoc)
	 * @see whf.framework.auth.entity.IPermission#setServiceOperation(java.lang.String)
	 */
	public void setServiceOperation(String serviceOperation) {
		this.serviceOperation = serviceOperation;
	}
	
	/* (non-Javadoc)
	 * @see whf.framework.entity.IPermissionable#getPermission()
	 */
	public Permission getPermission() {
		return this;
	}

	public String toString(){
		StringBuilder sb = new StringBuilder();
		sb.append("<").append(this.getId()).append(":").append(operation).append(" || ").append(serviceOperation).append("@").append(target).append(">");
		return sb.toString();
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}
}
